﻿using SrBBSPro.BaseClasses;
using SrBBSPro.Entities;
using System;

namespace SrBBSPro.Services
{
    public class UserService : BaseService<User,string>
    {

        /// <summary>
        /// 更新用户头像
        /// </summary>
        /// <param name="headPortrait"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public void UpdateHeadPortrait(string headPortrait, string StaffNo)
        {
            var response = new Response();

            DbBase.UpdateMany<User>().OnlyFields(p => p.HeadPortrait).Where(p => p.Id == StaffNo).Execute(new User
            {
                HeadPortrait = headPortrait
            });
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="StaffNo"></param>
        /// <returns></returns>
        public User Login(string StaffNo)
        {
            return DbBase.Query<User>().SingleOrDefault(p => p.Id == StaffNo);
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="StaffName">姓名</param>
        /// <returns></returns>
        public User GetUserByStaffName(string StaffName)
        {
            return DbBase.Query<User>().SingleOrDefault(p => p.StaffName == StaffName);
        }

        /// <summary>
        /// 检查工号是否已存在
        /// </summary>
        /// <param name="StaffNo"></param>
        /// <returns></returns>
        public bool CheckStaffNoIsExists(string StaffNo)
        {
            if (string.IsNullOrEmpty(StaffNo))
                return false;
            return DbBase.Query<User>().Any(p => p.Id == StaffNo);
        }
        /// <summary>
        /// 检查姓名是否已存在
        /// </summary>
        /// <param name="StaffName"></param>
        /// <returns></returns>
        public bool CheckStaffNameIsExists(string StaffName)
        {
            if (string.IsNullOrEmpty(StaffName))
                return false;
            return DbBase.Query<User>().Any(p => p.StaffName == StaffName);
        }
    }
}
